package com.li.algorithm.leetcode.hot100;

import java.util.Arrays;

public class Test3 {
    public int longestConsecutive(int[] nums) {
        int max = -1;
        int pre = Integer.MAX_VALUE;
        int count = 0;
        Arrays.sort(nums);
        for (int num : nums) {
            if (pre == num) {
                continue;
            }
            if (pre + 1 != num) {
                if (count > max) {
                    max = count;
                }
                count = 0;
            }
            pre = num;
            count++;
        }
        if (count > max) {
            max = count;
        }
        return max;
    }
    public static void main(String[] args) {
        Test3 test3 = new Test3();
        int[] nums = {1,2,0,1};
        System.out.println(test3.longestConsecutive(nums));
    }
}
